package com.zkw;

public class TestApplication {

        public static void main(String[] args) {
            try {
                System.out.println("开始****************************");
//                String json = "{\"name\":\"测试SM4加密解密\",\"描述\":\"CSDN哈哈哈\"}";
                String json = "123456";
                System.out.println("加密前："+json);
//自定义的32位16进制秘钥
                String key = "1024lab__1024lab";
                //String cipher = Sm4Util.encryptEcb(key,json);//sm4加密
                String cipher = Sm4Smart.encrypt(json);
                System.out.println("加密后："+cipher);
                //System.out.println("校验："+Sm4Util.verifyEcb(key,cipher,json));//校验加密前后是否为同一数据
                //json = Sm4Util.decryptEcb(key,cipher);//解密
                String getPassword = "NzFlNWI2MjE5ODUyODAxOWM0OTI3ZDhkM2ZkNWY1ODY=";
                String requestPassword = Sm4Smart.decrypt(getPassword);
                System.out.println("解密后："+requestPassword);
                System.out.println("结束****************************");

                String getEmployeeUid = "cf1e361fd46741f5b2a09335cef50db8";
                //String getLoginPwd = "$argon2id$v=19$m=16384,t=2,p=1$d9yQEAhck+haKxP2ZtXocg$NEnw3D2Ly8UbYpy2odATLA4ZflZ1FKJjWCuOGrVE4PM";
                String password = generateSaltPassword(requestPassword, getEmployeeUid);
                String encodedPassword = Sm4Smart.getEncryptPwd(password);
                Boolean matchesPwd = Sm4Smart.matchesPwd(password, encodedPassword);
                System.out.println("password = " + password);
                System.out.println("encodedPassword = " + encodedPassword);
                System.out.println("matchesPwd = " + matchesPwd);

            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    public static String generateSaltPassword(String password, String employeeUid) {
        return password + "_" +
                employeeUid.toUpperCase() +
                "_" +
                employeeUid.toLowerCase();
    }
}
